package com.example.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.example.common.result.Result;
import com.example.entity.TBUser;
import com.example.remote.FeginClientTest;
import com.example.service.UserService;
import com.example.vo.UserVO;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @author: 扎马斯
 * @date: 2024年08月30日 09:50
 * @describe:
 */
@RestController
@RequestMapping("/user")
@Log4j2
public class UserController {

    @Autowired
    private UserService userService;
    @Autowired
    private FeginClientTest feginClientTest;

    @GetMapping("/get")
    public List<? extends Object> getUser(@RequestParam("id") int id) {
        TBUser one = userService.getOne(new QueryWrapper<TBUser>().lambda().eq(TBUser::getUserId, id));
        log.info("one" + one);
        List<TBUser> list = userService.list();
        List<UserVO> collect = list.stream().map(l -> {
            UserVO userVO = new UserVO();
            userVO.setMobile(l.getMobile());
            userVO.setUsername(l.getUsername());
            return userVO;
        }).collect(Collectors.toList());
        return collect;
    }


    @GetMapping("/feginTest01")
    public Result<?> feginTest01() {
        log.info(feginClientTest.feginTest());
        return Result.success("111");
    }

    @PostMapping("/test01")
    public Result<Void> test01() {
        return Result.success();
    }


}
